package org.csu.hotelsys.converter;

import org.csu.hotelsys.model.Roomkt;
import org.csu.hotelsys.service.RoomServiceYH;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

@Component
public class StringToRoomConverter implements Converter<String, Roomkt> {

    static final Logger logger = LoggerFactory.getLogger(StringToRoomConverter.class);

    @Autowired
    RoomServiceYH roomServiceYH;

    /**
     * Gets Room by Id
     */
    @NotNull
    @Override
    public Roomkt convert(@NotNull String element) {
        Roomkt roomkt = roomServiceYH.findById(Integer.parseInt(element));
        logger.info("Room : {}", roomkt.getName());
        return roomkt;
    }

}
